<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="father">
        <div class="one active" style="background-image: url(img/photo1.jpg);">
            <span>asdascas</span>
        </div>
        <div class="one" style="background-image: url(img/photo2.jpg);">
            <span>dasdassd</span>
        </div>
        <div class="one" style="background-image: url(img/photo3.jpg);">
            <span>sacsadad</span>
        </div>
        <div class="one" style="background-image: url(img/photo5.jpg);">
            <span>adsaxxds</span>
        </div>
        <div class="one" style="background-image: url(img/photo6.jpg);">
            <span>adsadasa</span>
        </div>
    </div>
</body>
<script>
    //获取元素
    var divs = document.querySelectorAll('.one');
    var span = document.querySelectorAll('span');
    // console.log(span)
    //绑定事件

    for (var i = 0; i < divs.length; i++) {
        divs[i].onclick = function () {
            for (var j = 0; j < divs.length; j++) {
                console.log(divs[j]);
                divs[j].classList.remove('active');
            }
            this.classList.add('active'); 
        }  
    }

</script>

</html>